<?php 
 include_once dirname(__FILE__)."/config.php";
 class aa_niveau_principal{
		 protected $_resultrequest;
		 protected $_cnn;
		 protected $_CODE_NIVEAU;
		 protected $_LIB_NIVEAU;
		 public function get_name_table(){ return "aa_niveau";}
		 public function get_name_CODE_NIVEAU(){ return "CODE_NIVEAU";}
		 public function get_name_LIB_NIVEAU(){ return "LIB_NIVEAU";}
		 public function set_CODE_NIVEAU($parametre){  $this->_CODE_NIVEAU=$parametre;}	
		 public function set_LIB_NIVEAU($parametre){  $this->_LIB_NIVEAU=$parametre;}	
		 public function get_resultrequest(){ return $this->_resultrequest;}
		 public function get_CODE_NIVEAU(){ return $this->_CODE_NIVEAU;}
		 public function get_LIB_NIVEAU(){ return $this->_LIB_NIVEAU;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 aa_niveau(
			LIB_NIVEAU)
 VALUES(
			'".$this->_LIB_NIVEAU."')";

$this->_resultrequest=$this->_cnn->query($sql);
 if(!$this->_resultrequest){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_LIB_NIVEAU)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
LIB_NIVEAU='".$this->_LIB_NIVEAU."'";
}
$sql="UPDATE 
aa_niveau SET 
 ".$sql."
								WHERE 1=1  AND CODE_NIVEAU ='".$this->_CODE_NIVEAU."'";

$this->_resultrequest=$this->_cnn->query($sql);
 if(!$this->_resultrequest){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
aa_niveau 
 
									WHERE 1=1  AND CODE_NIVEAU ='".$this->_CODE_NIVEAU."'";

$this->_resultrequest=$this->_cnn->query($sql);
 if(!$this->_resultrequest){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
aa_niveau ";

$this->_resultrequest=$this->_cnn->query($sql);
 if(!$this->_resultrequest){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		CODE_NIVEAU,
		LIB_NIVEAU
 FROM 
 aa_niveau";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_resultrequest=$this->_cnn->query($sql);
 if(!$this->_resultrequest){return $this->_cnn->get_erreurmsg();}else{return 'success';}
}

 public function countRowInTable($constraint="")
{

$sql=" SELECT 
  COUNT(*) AS total 
 FROM 
 aa_niveau ";
	$this->_resultrequest=$this->_cnn->query($sql);
$donnees_total=mysql_fetch_assoc($this->_resultrequest);
return $donnees_total['total'];
}
public function fetch_object(){
$row=mysql_fetch_object($this->_resultrequest);
 if($this->_resultrequest){
 if($row){
		$this->_CODE_NIVEAU=$row->CODE_NIVEAU;
		$this->_LIB_NIVEAU=$row->LIB_NIVEAU;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>